﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using FisApp.enums;

namespace FisApp
{
    public partial class FrmAyarlar : Form
    {
        #region Variables

        public int tab { get { return tabControlAyarlar.SelectedIndex; } }

        #endregion

        public FrmAyarlar()
        {
            InitializeComponent();
        }

        #region Methods ControlButon

        private void SetWhenNewButtonPressed()
        {
            btn_a_yeni.Enabled = false;
            btn_a_duzelt.Enabled = false;
            btn_a_sil.Enabled = false;
            btn_a_arama.Enabled = false;
            btn_a_kaydet.Enabled = true;
            btn_a_vazgec.Enabled = true;
        }

        private void SetWhenEditButtonPressed()
        {
            btn_a_yeni.Enabled = false;
            btn_a_duzelt.Enabled = false;
            btn_a_sil.Enabled = false;
            btn_a_arama.Enabled = false;
            btn_a_kaydet.Enabled = true;
            btn_a_vazgec.Enabled = true;
        }

        private void SetWhenDeleteButtonPressed()
        {
            btn_a_yeni.Enabled = true;
            btn_a_duzelt.Enabled = true;
            btn_a_sil.Enabled = true;
            btn_a_arama.Enabled = true;
            btn_a_kaydet.Enabled = true;
            btn_a_vazgec.Enabled = true;
        }

        private void SetWhenSearchButtonPressed()
        {
            btn_a_yeni.Enabled = true;
            btn_a_duzelt.Enabled = true;
            btn_a_sil.Enabled = true;
            btn_a_arama.Enabled = true;
            btn_a_kaydet.Enabled = true;
            btn_a_vazgec.Enabled = true;
        }

        private void SetWhenSaveButtonPressed()
        {
            btn_a_yeni.Enabled = true;
            btn_a_arama.Enabled = true;
            btn_a_duzelt.Enabled = true;
            btn_a_kaydet.Enabled = true;
            btn_a_sil.Enabled = true;
            btn_a_vazgec.Enabled = true;

            gb_modelGiris.Enabled = false;
        }

        private void SetWhenCancelButtonPressed()
        {
            btn_a_yeni.Enabled = true;
            btn_a_arama.Enabled = true;
            btn_a_duzelt.Enabled = true;
            btn_a_kaydet.Enabled = true;
            btn_a_sil.Enabled = true;
            btn_a_vazgec.Enabled = true;
        }

        #endregion

        #region Methods ControlForm

        #region New

        private void SetWhenNewButtonPressedForSettings()
        {
            //TODO
        }

        private void SetWhenNewButtonPressedForAstar()
        {
            gb_astarArama.Enabled = false;
            gb_astarGiris.Enabled = true;
        }

        private void SetWhenNewButtonPressedForDeri()
        {
            gb_deriArama.Enabled = false;
            gb_deriGiris.Enabled = true;
        }

        private void SetWhenNewButtonPressedForRenk()
        {
            gb_renkArama.Enabled = false;
            gb_renkGiris.Enabled = true;
        }

        private void SetWhenNewButtonPressedForTaban()
        {
            gb_tabanArama.Enabled = false;
            gb_tabanGiris.Enabled = true;
        }

        private void SetWhenNewButtonPressedForModel()
        {
            gb_modelArama.Enabled = false;
            gb_modelGiris.Enabled = true;
        }
        #endregion

        #region Edit

        private void SetWhenEditButtonPressedForSettings()
        {
            //TODO
        }

        private void SetWhenEditButtonPressedForAstar()
        {
            gb_astarArama.Enabled = false;
            gb_astarGiris.Enabled = true;
        }

        private void SetWhenEditButtonPressedForDeri()
        {
            gb_deriArama.Enabled = false;
            gb_deriGiris.Enabled = true;
        }

        private void SetWhenEditButtonPressedForRenk()
        {
            gb_renkArama.Enabled = false;
            gb_renkGiris.Enabled = true;
        }

        private void SetWhenEditButtonPressedForTaban()
        {
            gb_tabanArama.Enabled = false;
            gb_tabanGiris.Enabled = true;
        }

        private void SetWhenEditButtonPressedForModel()
        {
            gb_modelArama.Enabled = false;
            gb_modelGiris.Enabled = true;
        }
        #endregion

        #region Delete


        private void SetWhenDeleteButtonPressedForSettings()
        {
            //TODO
        }

        private void SetWhenDeleteButtonPressedForAstar()
        {
            gb_astarArama.Enabled = false;
            gb_astarGiris.Enabled = false;
        }

        private void SetWhenDeleteButtonPressedForDeri()
        {
            gb_deriArama.Enabled = false;
            gb_deriGiris.Enabled = false;
        }

        private void SetWhenDeleteButtonPressedForRenk()
        {
            gb_renkArama.Enabled = false;
            gb_renkGiris.Enabled = false;
        }

        private void SetWhenDeleteButtonPressedForTaban()
        {
            gb_tabanArama.Enabled = false;
            gb_tabanGiris.Enabled = false;
        }

        private void SetWhenDeleteButtonPressedForModel()
        {
            gb_modelArama.Enabled = false;
            gb_modelGiris.Enabled = false;
        }
        #endregion

        #region Search


        private void SetWhenSearchButtonPressedForSettings()
        {
            //TODO
        }

        private void SetWhenSearchButtonPressedForAstar()
        {
            gb_astarArama.Enabled = true;
            gb_astarGiris.Enabled = false;
        }

        private void SetWhenSearchButtonPressedForDeri()
        {
            gb_deriArama.Enabled = true;
            gb_deriGiris.Enabled = false;
        }

        private void SetWhenSearchButtonPressedForRenk()
        {
            gb_renkArama.Enabled = true;
            gb_renkGiris.Enabled = false;
        }

        private void SetWhenSearchButtonPressedForTaban()
        {
            gb_tabanArama.Enabled = true;
            gb_tabanGiris.Enabled = false;
        }

        private void SetWhenSearchButtonPressedForModel()
        {
            gb_modelArama.Enabled = true;
            gb_modelGiris.Enabled = false;
        }
        #endregion

        #region Save
        private void SetWhenSaveButtonPressedForSettings()
        {
            //TODO
        }

        private void SetWhenSaveButtonPressedForAstar()
        {
            gb_astarArama.Enabled = false;
            gb_astarGiris.Enabled = true;
        }

        private void SetWhenSaveButtonPressedForDeri()
        {
            gb_deriArama.Enabled = false;
            gb_deriGiris.Enabled = true;
        }

        private void SetWhenSaveButtonPressedForRenk()
        {
            gb_renkArama.Enabled = false;
            gb_renkGiris.Enabled = true;
        }

        private void SetWhenSaveButtonPressedForTaban()
        {
            gb_tabanArama.Enabled = false;
            gb_tabanGiris.Enabled = true;
        }

        private void SetWhenSaveButtonPressedForModel()
        {
            gb_modelArama.Enabled = false;
            gb_modelGiris.Enabled = true;
        }
        #endregion

        #region Cancel


        private void SetWhenCancelButtonPressedForSettings()
        {
            //TODO
        }

        private void SetWhenCancelButtonPressedForAstar()
        {
            gb_astarArama.Enabled = false;
            gb_astarGiris.Enabled = false;
        }

        private void SetWhenCancelButtonPressedForDeri()
        {
            gb_deriArama.Enabled = false;
            gb_deriGiris.Enabled = false;
        }

        private void SetWhenCancelButtonPressedForRenk()
        {
            gb_renkArama.Enabled = false;
            gb_renkGiris.Enabled = false;
        }

        private void SetWhenCancelButtonPressedForTaban()
        {
            gb_tabanArama.Enabled = false;
            gb_tabanGiris.Enabled = false;
        }

        private void SetWhenCancelButtonPressedForModel()
        {
            gb_modelArama.Enabled = false;
            gb_modelGiris.Enabled = false;
        }
        #endregion

        #endregion

        #region Methods DB

        private bool SaveModel()
        {
            try
            {
                if (String.IsNullOrEmpty(txt_kaliteNo.Text))
                {
                    MessageBox.Show("Lütfen Model No giriniz.");
                    return false;
                }

                if (String.IsNullOrEmpty(txt_kalipNo.Text))
                {
                    MessageBox.Show("Lütfen Kalıp No giriniz.");
                    return false;
                }

                //DB.Uygula("INSERT INTO model (model_no, kalip_no) VALUES ('" + txt_kaliteNo.Text + "','" + txt_kalipNo.Text + "')", "");
                return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private bool SaveTaban()
        {
            try
            {
                if (String.IsNullOrEmpty(txt_kaliteNo.Text))
                {
                    MessageBox.Show("Lütfen Model No giriniz.");
                    return false;
                }

                if (String.IsNullOrEmpty(txt_kalipNo.Text))
                {
                    MessageBox.Show("Lütfen Kalıp No giriniz.");
                    return false;
                }

                //DB.Uygula("INSERT INTO model (model_no, kalip_no) VALUES ('" + txt_kaliteNo.Text + "','" + txt_kalipNo.Text + "')", "");
                return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private bool SaveSettings()
        {
            throw new NotImplementedException();
        }

        private bool SaveAstar()
        {
            throw new NotImplementedException();
        }

        private bool SaveDeri()
        {
            throw new NotImplementedException();
        }

        private bool SaveRenk()
        {
            throw new NotImplementedException();
        }

        private bool DeleteSettings()
        {
            throw new NotImplementedException();
        }

        private bool DeleteAstar()
        {
            throw new NotImplementedException();
        }

        private bool DeleteDeri()
        {
            throw new NotImplementedException();
        }

        private bool DeleteRenk()
        {
            throw new NotImplementedException();
        }

        private bool DeleteTaban()
        {
            throw new NotImplementedException();
        }

        private bool DeleteModel()
        {
            throw new NotImplementedException();
        }

        #endregion

        #region Events

        private void FrmAyarlar_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dBDataSet_model.model' table. You can move, or remove it, as needed.
            //this.modelTableAdapter.Fill(this.dBDataSet_model.model);
            //string conStr = @"Server=.\SQLEXPRESS; AttachDbFilename=|DataDirectory|DB.mdf; Database=DB;Trusted_Connection=Yes";
            //DB.DBConnectionString = conStr;

            gb_modelArama.Enabled = false;
            gb_modelGiris.Enabled = false;
        }

        private void btn_a_yeni_Click(object sender, EventArgs e)
        {
            try
            {
                if (tab == Tab.MODEL)
                {
                    SetWhenNewButtonPressedForModel();
                }
                else if (tab == Tab.TABAN)
                {
                    SetWhenNewButtonPressedForTaban();
                }
                else if (tab == Tab.RENK)
                {
                    SetWhenNewButtonPressedForRenk(); 
                }
                else if (tab == Tab.DERI)
                {
                    SetWhenNewButtonPressedForDeri();
                }
                else if (tab == Tab.ASTAR)
                {
                    SetWhenNewButtonPressedForAstar();
                }
                else if (tab == Tab.SETTINGS)
                { 
                    SetWhenNewButtonPressedForSettings();
                }

                SetWhenNewButtonPressed();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Problem oluştu. Hata :" + ex.Message, "HATA", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }  
        }

        private void btn_a_kaydet_Click(object sender, EventArgs e)
        {
            try
            {
                if (tab == Tab.MODEL)
                {
                    if (SaveModel())
                    {
                        SetWhenSaveButtonPressedForModel();
                    }
                }
                else if (tab == Tab.TABAN)
                {
                    if (SaveTaban())
                    {
                        SetWhenSaveButtonPressedForTaban();
                    }
                }
                else if (tab == Tab.RENK)
                {
                    if (SaveRenk())
                    {
                        SetWhenSaveButtonPressedForRenk();
                    }
                }
                else if (tab == Tab.DERI)
                {
                    if (SaveDeri())
                    {
                        SetWhenSaveButtonPressedForDeri();
                    }
                }
                else if (tab == Tab.ASTAR)
                {
                    if (SaveAstar())
                    SetWhenSaveButtonPressedForAstar();
                }
                else if (tab == Tab.SETTINGS)
                {
                    if(SaveSettings())
                    SetWhenSaveButtonPressedForSettings();
                }
                

                SetWhenSaveButtonPressed();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Kayıt işlemi yaparken problem oluştu. Hata :" + ex.Message, "HATA", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void btn_a_duzelt_Click(object sender, EventArgs e)
        {
            try
            {
                if (tab == Tab.MODEL)
                {
                    SaveModel();
                    SetWhenSaveButtonPressedForModel();
                }
                else if (tab == Tab.TABAN)
                {
                    SaveTaban();
                    SetWhenSaveButtonPressedForTaban();
                }
                else if (tab == Tab.RENK)
                {
                    SaveRenk();
                    SetWhenSaveButtonPressedForRenk();
                }
                else if (tab == Tab.DERI)
                {
                    SaveDeri();
                    SetWhenSaveButtonPressedForDeri();
                }
                else if (tab == Tab.ASTAR)
                {
                    SaveAstar();
                    SetWhenSaveButtonPressedForAstar();
                }
                else if (tab == Tab.SETTINGS)
                {
                    SaveSettings();
                    SetWhenSaveButtonPressedForSettings();
                }

                SetWhenEditButtonPressed();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Modeli kaydederken problem oluştu. Hata :" + ex.Message, "HATA", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
           
        }

        private void btn_a_sil_Click(object sender, EventArgs e)
        {
            try
            {
                if (tab == Tab.MODEL)
                {
                    DeleteModel();
                }
                else if (tab == Tab.TABAN)
                {
                    DeleteTaban();
                }
                else if (tab == Tab.RENK)
                {
                    DeleteRenk();
                }
                else if (tab == Tab.DERI)
                {
                    DeleteDeri();
                }
                else if (tab == Tab.ASTAR)
                {
                    DeleteAstar();
                }
                else if (tab == Tab.SETTINGS)
                {
                    DeleteSettings();
                }

                SetWhenDeleteButtonPressed();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Silme işleminde problem oluştu. Hata :" + ex.Message, "HATA", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }


        private void btn_a_arama_Click(object sender, EventArgs e)
        {
            SetWhenSearchButtonPressed();
        }

        private void btn_a_vazgec_Click(object sender, EventArgs e)
        {
            SetWhenCancelButtonPressed();
        }

        #endregion
    }
}
